package com.shen.langchain4j.config;

import dev.langchain4j.data.segment.TextSegment;
import dev.langchain4j.model.embedding.EmbeddingModel;
import dev.langchain4j.model.openai.OpenAiEmbeddingModel;
import dev.langchain4j.store.embedding.EmbeddingStore;
import dev.langchain4j.store.embedding.qdrant.QdrantEmbeddingStore;
import io.qdrant.client.QdrantClient;
import io.qdrant.client.QdrantGrpcClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 大模型配置类
 */
@Configuration
public class LLMConfig {
    /**
     * 嵌入(向量化)模型
     *
     * @return 嵌入模型
     */
    @Bean
    public EmbeddingModel embeddingModel() {
        return OpenAiEmbeddingModel.builder()
                .apiKey(System.getenv("aliyunQwen-apiKey"))
                .modelName("text-embedding-v4")
                .baseUrl("https://dashscope.aliyuncs.com/compatible-mode/v1")
                .build();
    }

    /**
     * qdrant客户端
     *
     * @return qdrant客户端
     */
    @Bean
    public QdrantClient qdrantClient() {
        QdrantGrpcClient.Builder clientBuilder = QdrantGrpcClient
                .newBuilder("47.115.218.172", 6334, false);
        return new QdrantClient(clientBuilder.build());
    }

    /**
     * 向量数据库
     *
     * @return 向量数据库
     */
    @Bean
    public EmbeddingStore<TextSegment> embeddingStore() {
        return QdrantEmbeddingStore.builder()
                .host("47.115.218.172")
                .port(6334)
                .collectionName("test-qdrant")
                .build();
    }
}
